package com.demo.core.service;

import com.demo.base.page.IPagableDTO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.demo.base.model.PublicNotice;
import com.demo.base.page.IPagableDTO;
import com.demo.core.dao.PublicMessageDao;

/**
 * Created by jiandandia on 2017/4/5.
 */
@Transactional
@Service
public class PublicMessageService {
    @Autowired
    private PublicMessageDao publicMessageDao;

    public PublicNotice saveOrUpdatePublicNotice(PublicNotice publicNotice) throws Exception{
        return publicMessageDao.saveOrUpdatePublicNotice(publicNotice);
    }

    public boolean addBrowsingNumber(String noticeId){
        return publicMessageDao.addBrowsingNumber(noticeId);
    }

    public boolean addFollowersNumber(String noticeId){
        return publicMessageDao.addFollowersNumber(noticeId);
    }

    public void closePublicNotice(String id) throws Exception{
        publicMessageDao.closePublicNotice(id);
    }

    public IPagableDTO<PublicNotice> queryPublicNotices(String query, IPagableDTO pagableDTO){
        return publicMessageDao.queryPublicNotices(query, pagableDTO);
    }

    public void deltePublicNoticesById(String ids) throws Exception{
        String[] idss = StringUtils.split(ids,',');
        for (String id : idss) {
            publicMessageDao.deltePublicNoticesById(id);
        }
    }
}
